import config
import consumer
from builder import Builder

from oslo_config import cfg
from oslo_log import log as logging


LOG = logging.getLogger(__name__)

class Manager(object):

    def __init__(self):
        config.load_config()

        self.cnsm = None
        if cfg.CONF.csv_file:
            self.cnsm = consumer.get_consumer(
                'csv', csv_file=cfg.CONF.csv_file
            )

        self.builder = Builder()

    def recreate_loadbalancers(self):
        lb_ids = self.cnsm.get_loadbalancer_ids()
        loadbalancer_id = "6f087bb1-0f32-4001-a056-8c0ffce2dbad"
        self.builder.rebuild_loadbalancers(
            [loadbalancer_id]
        )

    def recreate_listeners(self):
        ls_ids = self.cnsm.get_listener_ids()
        listener_id = "69d6776f-63c8-4d88-b120-e3b212d26976"
        self.builder.rebuild_listeners(
            [listener_id]
        )

    def recreate_pools(self):
        ls_ids = self.cnsm.get_pool_ids()
        pool_id = "2ff892ab-355d-4464-a6d7-85074b9a60e4"
        self.builder.rebuild_pools(
            [pool_id]
        )

    def recreate_members(self):
        ls_ids = self.cnsm.get_member_ids()
        member_id = "9b05afa9-eb74-4d44-88b6-574497c036e7"
        self.builder.rebuild_members(
            [member_id]
        )

    def start(self):
        self.recreate_loadbalancers()

        self.recreate_members()
        self.recreate_pools()
        self.recreate_listeners()


if __name__ == "__main__":
    manager = Manager()
    manager.start()
